﻿package mortal.game.view.group.panel
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.group.cellRenderer.*;
    import mortal.mvc.core.*;

    public class NearTeamsPanel extends GSprite
    {
        private var _teamList:GTileList;
        private var _refreshBtn:GButton;

        public function NearTeamsPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(13, 65, 778, 325, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(10, 66, 788, 22, this, ImagesConst.RegionTitleBg));
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = AlignMode.CENTER;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30212), 0, 67, 160, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30213), 195, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30214), 330, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30215), 460, 67, 115, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30216), 695, 67, 100, 20, this));
            this._teamList = UIFactory.tileList(22, 93, 750, 287, this);
            this._teamList.rowHeight = 30;
            this._teamList.columnWidth = 740;
            this._teamList.horizontalGap = 1;
            this._teamList.verticalGap = 1;
            this._teamList.setStyle("skin", new Bitmap());
            this._teamList.setStyle("cellRenderer", NearTeamCellRenderer);
            this.addChild(this._teamList);
            this._refreshBtn = UIFactory.gButton(Language.getString(30210), 363, 396, 65, 22, this);
            this._refreshBtn.configEventListener(MouseEvent.CLICK, this.refreshTeamInfo);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._teamList.dispose(param1);
            this._refreshBtn.dispose(param1);
            this._teamList = null;
            this._refreshBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function getDateProvider() : DataProvider
        {
            var _loc_3:SGroup = null;
            var _loc_4:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.group.nearTeamList;
            _loc_2.sort(this.groupSort);
            for each (_loc_3 in _loc_2)
            {
                
                _loc_4 = {data:_loc_3};
                _loc_1.addItem(_loc_4);
            }
            return _loc_1;
        }// end function

        private function groupSort(param1:SGroup, param2:SGroup) : int
        {
            if (param1.copyCode && param2.copyCode == 0)
            {
                return 1;
            }
            if (param1.copyCode == 0 && param2.copyCode)
            {
                return -1;
            }
            if (param1.players.length == 5 && param2.players.length < 5)
            {
                return 1;
            }
            if (param1.players.length < 5 && param2.players.length == 5)
            {
                return -1;
            }
            return 0;
        }// end function

        private function refreshTeamInfo(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GroupGetNearTeam));
            return;
        }// end function

        public function updateTeamList() : void
        {
            this._teamList.dataProvider = this.getDateProvider();
            this._teamList.drawNow();
            return;
        }// end function

    }
}
